package com.flyme.module.base.provider.controller;

import com.flyme.common.core.model.ResultBody;
import com.flyme.common.core.model.query.CriteriaQuery;
import com.flyme.common.core.model.query.PagerInfo;
import com.flyme.common.core.model.query.PqGrid;
import com.flyme.core.base.supper.controller.BaseController;
import com.flyme.core.base.supper.entity.EntityMap;
import com.flyme.module.base.client.api.SysAuthorizeRemoteService;
import com.flyme.module.base.client.entity.SysAuthority;
import com.flyme.module.base.provider.service.SysAuthorizeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author: zyf
 * @date: 2018/11/26 18:20
 * @description:
 */
@Api(tags = "授权管理")
@RestController
public class SysGrantAccessController extends BaseController<SysAuthorizeService, SysAuthority> implements SysAuthorizeRemoteService {

    /**
     * 获取已授权访问列表
     *
     * @return
     */
    @ApiOperation(value = "获取已授权访问分页列表",notes = "获取已授权访问分页列表")
    @ApiImplicitParams({@ApiImplicitParam(name = "pagerInfo", value = "分页对象", paramType = "form"), @ApiImplicitParam(name = "keyword", value = "查询字段", paramType = "form"),})
    @PostMapping("/grant/access")
    @Override
    public PqGrid grantAccess(@RequestParam(value = "pagerInfo", required = false, defaultValue = "1") PagerInfo pagerInfo, @RequestParam(name = "keyword", required = false) String keyword) {
        CriteriaQuery cq = new CriteriaQuery<EntityMap>(pagerInfo);
        return bizService.pageList(cq);
    }

    /**
     * 获取已授权访问列表
     *
     * @return 应用信息
     */
    @ApiOperation(value = "获取已授权访问列表",notes = "获取已授权访问列表")
    @GetMapping("/grant/access/list")
    @Override
    public ResultBody<List<SysAuthority>> grantAccessList() {
        return ResultBody.success(bizService.getGrantAccessList());
    }


}
